<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<!DOCTYPE html>
<html lang="en">
	<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta http-equiv="Content-Type" content="multipart/form-data; charset=UTF-8">
	<meta charset="utf-8">
	<script type="text/javascript" src="${ctx}/static/threadui/js/jquery-1.11.3.js"></script>
	<script type="text/javascript" src="${ctx}/static/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${ctx}/static/tools/jquery-validationEngine/jquery.validationEngine.js"></script>
    <script type="text/javascript" src="${ctx}/static/tools/jquery-validationEngine/jquery.validationEngine-cn.js"></script>
	<title>中铁十四局一公司</title>
	</head>
	
	<body>
	
	<form	id="mechanicalApply" onsubmit="return wxMechanApply();" method="post" action="${ctx}/mechanicalApply/save" enctype="multipart/form-data">
		<div style="height:30px"><i>里程桩号：</i><input name="mileageCode" id="mileageCode" type="text" maxlength="50"/></div>
		<div style="height:30px"><i>申请内容：</i><input name="applyContent" id="applyContent" type="text" maxlength="50"/></div>
		<div style="height:30px"><i>机械类型：</i>
		<select name="mechanicalId" id="mechanicalId">
		<c:forEach var="res" items="${res.data.rows}" varStatus="status">
			<option value="${res.mechanicalId}">${res.mechanicalName}-${res.mechanicalModel}</option>
		</c:forEach>
		</select>
		<div style="height:30px"><i>工程类别：</i>
		<select name="projectId" id="projectId">
			<option value="1">路基</option>
			<option value="2">路面</option>
			<option value="3">桥涵</option>
			<option value="4">隧道</option>
			<option value="5">其他</option>
		</select>
		</div>
		<div style="height:30px"><i>使用时间从：</i>
		
		<input id="startTime" name="startTime" class="Wdate validate[required,maxSize[100]]" type="text" onFocus="var endTime=$dp.$('endTime');WdatePicker({onpicked:function(){endTime.focus();},dateFmt:'yyyy-MM-dd HH',maxDate:'#F{$dp.$D(\'endTime\')}'})"/>
至
<input id="endTime" name="endTime" class="Wdate validate[required,maxSize[100]]" type="text" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'startTime\')}',dateFmt:'yyyy-MM-dd HH'})"/>
		
		<div style="height:30px"><i>工时：</i><input name="useHours" id="useHours" type="text" maxlength="50"/></div>
		<div style="height:30px"><i>单价：</i><input name="price" id="price" type="text" class="validate[required,maxSize[100]]" maxlength="50"/></div>
		<div style="height:30px"><i>机械数量：</i><input name="quantity" id="quantity" type="text" class="validate[required,maxSize[100]]" maxlength="50"/></div>
		<div style="height:30px"><i>总费用：</i><input name="fee" id="fee" type="text" maxlength="50"/></div>
		<div style="height:30px"><i>施工队ID：</i>
		
		<select id="constructionId" name="constructionId">
									<option class="department_opt" value="">选择施工队</option>
									<c:forEach var="res" items="${constructionteams.data}">
										<option class="department_opt" value="${res.teamId }">${res.name }</option>
									</c:forEach>
								</select>
		
		</div>
		
		<div style="height:30px"><i>前图片：</i><input name="frontImage" id="frontImage" class="text-field" type="file" required="true" vtype="/.+(jpg|jpeg|png)$/" title="图片只支持jpg,jpeg和png格式"></div>
		<div style="height:30px"><i>中图片：</i><input name="middleImage" id="middleImage" class="text-field" type="file" required="true" vtype="/.+(jpg|jpeg|png)$/" title="图片只支持jpg,jpeg和png格式"></div>
		<div style="height:30px"><i>后图片：</i><input name="behindImage" id="behindImage" class="text-field" type="file" required="true" vtype="/.+(jpg|jpeg|png)$/" title="图片只支持jpg,jpeg和png格式"></div>
		
		<div style="height:30px"><i>状态：</i><select id="status" name="status">
									<option class="department_opt" value="0">选择状态</option>
										<option class="department_opt" value="1">已申请</option>
										<option class="department_opt" value="2">审批中</option>
										<option class="department_opt" value="3">已批准</option>
								</select></div>
		
		<div style="height:30px"><i>申请时间：</i><input id="applyTime" name="applyTime" class="Wdate" type="text" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/></div>
		
		<div style="height:30px"><i>申请人：</i><input name="applyUserId" id="applyUserId" type="text" maxlength="50" value="${user.user_id}"/>${user.userName}</div>
		
		<a class="movie_continue">
						<input type="submit" name="submit" id="submit" value="提交" class="cinema_inquiry" />
					</a>
		
	</form>
	<script type="text/javascript">
			//项目基本信息修改
			function wxMechanApply(){
			var starttime=$("#startTime").val();
			var endtime=$("#endTime").val();
			starttime = starttime.replace(/-/g,"/");
			endtime = endtime.replace(/-/g,"/");
            var date1 = new Date(starttime);
            var date2 = new Date(endtime);
            var date3=date2.getTime()-date1.getTime();
            var leave1=date3%(24*3600*1000);    //计算天数后剩余的毫秒数
            var hours=Math.floor(leave1/(3600*1000));
            document.getElementById("useHours").value = hours;//设置时差
            document.getElementById("fee").value=$("#quantity").val()*$("price").val()*hours;//计算总费用
			
				if($("#mechanicalApply").validationEngine("validate")){
					
					
					
					var datastr = new Object();
	    			datastr.mileageCode = $('#mileageCode').val();
	    			datastr.applyContent = $('#applyContent').val();
	    			datastr.mechanicalId = $('#mechanicalId').val();
	    			datastr.projectId = $('#projectId').val();
	    			
	    			datastr.startTime = $('#startTime').val();
	    			datastr.endTime = $('#endTime').val();
	    			datastr.quantity = $('#quantity').val();
	    			datastr.constructionId = $('#constructionId').val();
	    			datastr.price = $('#price').val();
	    			
	    			datastr.frontImage = $('#frontImage').val();
	    			datastr.middleImage = $('#middleImage').val();
	    			datastr.behindImage = $('#behindImage').val();
	    			
	    			datastr.status = $('#status').val();
	    			datastr.applyTime = $('#applyTime').val();
	    			datastr.applyUserId = $('#applyUserId').val();
	    			
					var result = true;
					$.ajax({
	    		        async: true,
	    		        type:"POST",
	    		        data:JSON.stringify(datastr),
	    		        url: "${ctx}/mechanicalApply/save?&mid="+Math.random(),
	    		        dataType: "json",
	    		        
	    		        headers : {  
	                        'Content-Type' : 'multipart/form-data;charset=utf-8'  
	                    },
	                    
	                    success : function(data) {
	                		if (data != undefined && data.status != undefined
	                				&& data.status.trim() == '0') {
	                			result = true;
	                			alert("保存成功！");
	                			//window.location.href = "${ctx}/sys/sysProjectMan/ConstructionInfo/toSearch";
	                		} else {
	                			result = false;
	                			alert(data.data);
	                		}
	                	},
	    			},"json");
					
					
					
					/*$.ajax({
				        type: "POST",
				        dataType: "json",
				        ContentType: "multipart/form-data",
				        async: false,
				        url: '${ctx}/mechanicalApply/save',
				        data: $('#mechanicalApply').serialize(),
				        success: function (data) {
				        	if(data!=undefined&&data.status!=undefined&&data.status.trim()=='0'){
				        		result = true;
				        		alert("申请成功！");
				        		window.location.href = "${ctx}/wx/mechan/success";
				        	}else{
					        	result = false;
				        		alert(data.error);
				        	}
				        },
				        error: function(data) {
				        	result = false;
			        		alert(data.data);
				         }
				    });*/
				}
				return false;
			}
			$("#mechanicalApply").validationEngine();
		</script>
	</body>
	
</html>